package com.power.leopard.common.util;

public class VersionUtils {

	public static final String VERSION = "1.2";

	public static int compareVersion(String version1, String version2) {
		String[] split1 = version1.split("\\.|-");
		String[] split2 = version2.split("\\.|-");

		int len1 = split1.length;
		int len2 = split2.length;
		int compareCount = len1 < len2 ? len1 : len2;

		for (int i = 0; i < compareCount; i++) {
			String v1 = split1[i];
			String v2 = split2[i];

			int compare = 0;
			try {
				compare = Integer.compare(Integer.parseInt(v1), Integer.parseInt(v2));
			} catch (Exception e) {
				compare = v1.compareToIgnoreCase(v2);
			}
			if (compare != 0) {
				return compare;
			}
		}

		return len1 - len2;
	}

}
